#include <QVBoxLayout>
#include <QUrl>
#include <QLabel>

#include <qqrencode.h>

#include "qrwindow.h"

namespace Haha
{
class QRWindowPrivate
{
public:
    QLabel* widget = nullptr;
};

QRWindow::QRWindow(QWidget *parent) : QWidget(parent)
{
    d_ptr = new QRWindowPrivate;
    d_ptr->widget = new QLabel(this);
    QVBoxLayout* layout = new QVBoxLayout;
    layout->addWidget(d_ptr->widget);
    setLayout(layout);
}

QRWindow::~QRWindow()
{

}

QRWindow* QRWindow::instance()
{
    static QRWindow _inst;
    return &_inst;
}

void QRWindow::setUrl(const QUrl& url)
{
    QQREncode encoder;
    encoder.encode(url.toString());

    QImage img = encoder.toQImage(200);
    d_ptr->widget->setPixmap(QPixmap::fromImage(img));
}


} // namespace haha
